# Contributor: Alexander Edland <alpine@ocv.me>
# Contributor: Nicolas Lorin <androw95220@gmail.com>
# Maintainer:
pkgname=zimg
pkgver=3.0.3
pkgrel=1
pkgdesc="Scaling, colorspace conversion and dithering library"
url="https://github.com/sekrit-twc/zimg"
arch="all !s390x" # Tests fail on big-endian
license="WTFPL-2.0"
makedepends="autoconf automake libtool cmake linux-headers"
subpackages="$pkgname-doc $pkgname-dev"
source="zimg-$pkgver.tar.gz::https://github.com/sekrit-twc/zimg/archive/release-$pkgver.tar.gz
	zimg-gtest-1.11.0.tar.gz::https://github.com/google/googletest/archive/release-1.11.0.tar.gz
	musl-missing-include.patch
	"
builddir="$srcdir/zimg-release-$pkgver"
options="!check" # we run tests in the build stage

prepare() {
	default_prepare
	mkdir -p "$pkgdir"
	# googletest is required in-tree
	ln -s "$srcdir"/googletest-*/* test/extra/googletest
	autoreconf -vfi
}

build() {
	# build and run test binaries here
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-static \
		--enable-unit-test
	make
	make test/unit_test.log
	test/unit_test

	# build release binaries here without enabling tests,
	# as they make zimg slower
	make clean
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--disable-static
	make
}

package() {
	make -j1 DESTDIR="$pkgdir" install
}

sha512sums="
859c625599b412ecdd72c73d7618f6c7f9760337f7c8aec69fb97e30e1e65e4da51f6cbc5a2c8ad58cb7fbccdccb5322b95f24166c0204da6a3a8cd862cfb2ab  zimg-3.0.3.tar.gz
6fcc7827e4c4d95e3ae643dd65e6c4fc0e3d04e1778b84f6e06e390410fe3d18026c131d828d949d2f20dde6327d30ecee24dcd3ef919e21c91e010d149f3a28  zimg-gtest-1.11.0.tar.gz
06c1b1220e0418ed5051a6c594bbf48ba7ed10a4e2a95b51d6ae2451ba49b1f0be97347115c203fe82322c7f3b9f75756ba03eabe902898b3e3dd2c9e1765891  musl-missing-include.patch
"
